#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/11/6 19:54
# @Author  : 作者名:张铁君
# @Site    : 
# @File    : LoginPage.py
# @Project : h5_auto_test
# @Software: PyCharm
from selenium.webdriver.common.by import By
from time import sleep
from base.LoginBase import LoginBase
from base.ObjectMap import ObjectMap
from common.yaml_config import GetConf
from logs.log import log


class LoginPage(LoginBase, ObjectMap):
    def login_input_value(self, driver, input_placeholder, input_value):
        """
        登录页输入值
        :param driver:
        :param input_placeholder:
        :param input_value:
        :return:
        """
        log.info("输入：" + input_placeholder + "为：" + str(input_value))
        input_xpath = self.login_account_input(input_placeholder)
        return self.element_fill_value(driver, By.XPATH, input_xpath, input_value, 30)

    def login_click(self, driver):
        """
        点击登录按钮
        :param driver:
        :param button:
        :return:
        """
        log.info("点击登录")
        button_xpath = self.login_button()
        return self.element_click(driver, By.XPATH, button_xpath)

    def to_login(self, driver, user, pwd, url="https://caasyun.com/login"):
        """
        跳转到登录页面
        :param deiver:
        :param user:
        :return:
        """
        log.info("跳转登录页面")
        self.element_to_url(driver, url)
        self.save_screenshot1(driver)
        self.login_input_value(driver, "用户名", user)
        self.save_screenshot1(driver)
        self.login_input_value(driver, "密码", pwd)
        self.save_screenshot1(driver)
        self.login_click(driver)
        sleep(1)
        # self.assert_login_success(driver)
